package org.witsoft.demo.graphql.service.impl;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.witsoft.demo.graphql.entity.User;
import org.witsoft.demo.graphql.model.UserInput;
import org.witsoft.demo.graphql.repository.UserRepository;
import org.witsoft.demo.graphql.service.UserService;

@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

    private final UserRepository userRepository;

    public User verify(String email, String pwd){
        return userRepository.findFirstByEmailAndPwd(email, pwd);
    }

    @Override
    public User save(UserInput input) {
        User user = new User();
        BeanUtils.copyProperties(input, user);
        userRepository.save(user);
        return user;
    }
}
